const fs = require("fs");
const readline = require("readline");
let asinData = [];
let i= 1;
function readAsin() {
    const r1 = readline.createInterface({
      input: fs.createReadStream("./data/" + "USb2" + ".txt"),
    });
    r1.on("line", function (line) { //事件监听
      asinData.push(line);
      i++;
    });
    r1.on("close", function () {
      console.log(i);
      let AData = unique(asinData);
      console.log("jkjkjk");
      console.log(AData.length);
      AData.forEach((asin, index) => {
        if(index % 2 === 0 ){
          fs.appendFileSync("./data/USb2_a.txt", asin + "\n", "utf8");
        }
        else{
          fs.appendFileSync("./data/USb2_b.txt", asin + "\n", "utf8");
        }
      });
      console.log("ok");

    });




}

function unique(arr) {
  let res = [];
  let json = {};
  for (let i = 0; i < arr.length; i++) {
    if (!json[arr[i]]) {
      // console.log(arr[i])
      res.push(arr[i]);
      json[arr[i]] = 1;
    }
  }
  return res;
}


readAsin();
